﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace YAMN_Cinemas.Presentation
{
    public partial class sample : System.Web.UI.Page
    {
        private TheatreEntities entities;
        protected void Page_Load(object sender, EventArgs e)
        {
            entities = new TheatreEntities();

            List<Movy> movies = entities.Movies.ToList<Movy>();

            int row = 0;
            if ((movies.Count % 4) == 0)
                row = movies.Count / 4;
            else
                row = (movies.Count / 4) + 1;

            int columnCount = 0;
            Table table = new Table();
            for (int r = 0; r < row; r++)
            {
                TableRow tblRow = new TableRow();
                for (int c = 0; c < 4; c++)
                {
                    if (columnCount < movies.Count)
                    {
                        TableCell cell = new TableCell();
                        MovieView movieView = (MovieView)Page.LoadControl("~/presentation/MovieView.ascx");

                        Movy movy = movies[columnCount++];
                        movieView.ImageUrl = "../images/" + movy.Movie_Title + ".jpg";
                        movieView.Title = movy.Movie_Title;
                        movieView.MovieUrl = "Admin_EditMovie1.aspx";
                        movieView.FromDate = movy.FromDate.ToString("dd/MM/yyyy");
                        movieView.ToDate = movy.ToDate.ToString("dd/MM/yyyy");
                        movieView.Language = movy.Language;
                        movieView.Duration = movy.Duration;
                        cell.Controls.Add(movieView);
                        tblRow.Cells.Add(cell);
                    }
                    else
                        break;

                    table.Rows.Add(tblRow);
                    table.Attributes.Add("width", "100%");
                    moviePanel.Controls.Add(table);
                }
            }

        }
    }
}